from DB import db_hand
import time
def select_money(login_user):
    user_data=db_hand.get_data(login_user)
    return user_data['money']


def take_money(login_user,money):
    user=db_hand.get_data(login_user)
    if user['money']>=money:
        user['money']-=money
        print('取款成功')
        now_time=time.strftime('%x %X')
        acc_info=f"{now_time} {login_user}取款{money}元，当前余额为{user['money']}"
        user['account'].append(acc_info)
        db_hand.save_data(user)
        return True,acc_info
    return False,'当前余额不足'

def recharge(login_user,money):
    user=db_hand.get_data(login_user)
    user['money']+=money
    now_time=time.strftime('%x %X')
    acc_info=f"{now_time} {login_user}存了{money}元，当前余额为{user['money']}"
    user['account'].append(acc_info)
    db_hand.save_data(user)
    return True,acc_info

def get_acc(user_name):
    user_data=db_hand.get_data(user_name)
    return user_data['account']


